﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraBars;
using Event;
using DevExpress.XtraTreeList.Nodes;
using RequestDebug;
using Data;
using Git;
using GitFrom;

namespace HTTPRequest2
{
    public partial class index : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public index()
        {
            InitializeComponent();
            EventGlobal.EvIndexTabbedViewOpenNew += new EventGlobal.DeIndexTabbedViewOpenNew(SetOpenNewTab);
            
            //分支管理
            FromBranch fb = new FromBranch();
            fb.branch(barSubItem_git, this.dockManager1);

        }


        /// <summary>
        /// 事件触发
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="tln"></param>
        public void SetOpenNewTab(string id, string title, TreeListNode tln)
        {

            DevExpress.XtraBars.Docking.ControlContainer dockPanel5_Container = new DevExpress.XtraBars.Docking.ControlContainer();
            DevExpress.XtraBars.Docking.DockPanel dockPanel5 = new DevExpress.XtraBars.Docking.DockPanel();
            dockPanel5_Container.Name = GUID.getGUID();
            dockPanel5.Controls.Add(dockPanel5_Container);
            dockPanel5.Name = GUID.getGUID();
            dockPanel5.Tag = tln;
            dockPanel5.SavedIndex = dockPanel5.Index + 1;
            dockPanel5.Text = title;
            dockPanel5.Dock = DevExpress.XtraBars.Docking.DockingStyle.Fill;

            this.tabbedView1.BeginUpdate();
            this.dockManager1.AddPanel(DevExpress.XtraBars.Docking.DockingStyle.Float, dockPanel5);
            
            DevExpress.XtraBars.Docking2010.Views.BaseDocument document = this.tabbedView1.AddDocument(dockPanel5);
            this.tabbedView1.ActivateDocument(dockPanel5);

            RequestDebugControl sd = new RequestDebugControl()
            {
                Size = new Size(5000, 5000),
                Location = new Point(0, 0),
                Dock = DockStyle.Fill
            };
            sd.BuildRequestDebug(id, title, tln, dockPanel5);
            dockPanel5.Controls.Add(sd);
            this.tabbedView1.EndUpdate();

        }

        private void tabbedView1_DocumentClosing(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentCancelEventArgs e)
        {
            if (e.Document.Control.Tag != null)
            {
                TreeListNode tn = (TreeListNode)e.Document.Control.Tag;
                tn.SetValue("opendnumber", (tn.GetValue("opendnumber") == null ? 1 : (int)tn.GetValue("opendnumber")) - 1);
            }
        }

        private void barButtonItem_全局代码_ItemClick(object sender, ItemClickEventArgs e)
        {
            GlobalCode.GlobalCode xd = new GlobalCode.GlobalCode();
            xd.StartPosition = FormStartPosition.CenterParent;
            xd.ShowDialog();
        }

        /// <summary>
        /// 收缩所有节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dockPanel_目录_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e)
        {
            this.requserDirectory1.treeListNodeCollapseAll();
        }

        /// <summary>
        /// 打开Git配置窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItem_git_ItemClick(object sender, ItemClickEventArgs e)
        {
            //this.barSubItem_git;
            //BarSubItem barSubItem_slave = (BarSubItem)this.barSubItem_git.ItemLinks[1];
            /*BarButtonItem bi = new BarButtonItem();
            bi.Caption = "barButtonItem1";
            bi.Name = "barButtonItem1";
            this.barSubItem_master.AddItem(bi);*/
            GitConfig.GitConfig g = new GitConfig.GitConfig();
            g.ShowDialog();
        }

    }
}